
<fieldset>
    <legend>Course Photo</legend>

    <div class="row">
        <?php
        $this->widget('xupload.XUpload', array(
            'url' => Yii::app()->createUrl("Courses/upload"),
            'model' => $photos,
            'htmlOptions' => array('id' => 'courses-form'),
            'attribute' => 'file',
            'multiple' => true,
            'showForm' => false,
                )
        );
        ?>

        <div>
            <?php
            if (isset($_GET['id'])) {
                $courseWithImage = Courses::getCourseWithImage($_GET['id']);
                $dataProvider = new CArrayDataProvider($courseWithImage, array(
                    'id' => 'courseimage',
                    'sort' => array(
                        'attributes' => array(
                            'id', 'photo', 'courses_id',),
                    ),
                    'pagination' => array(
                        'pageSize' => 10,),));


                $this->widget('zii.widgets.grid.CGridView', array(
                    'id' => 'courseimage-grid',
                    'dataProvider' => $dataProvider,
                    'columns' => array(
                        array(
                            'name' => 'Image',
                            'type' => 'image',
                            'value' => 'Courses::CourseImageingridViewBack($data)',
                            'htmlOptions' => array('style' => 'text-align: center'),
                        ),
                        array(
                            'name' => 'Primary image',
                            'type' => 'raw',
                            'value' => 'Courses::changeStatusIngridView($data)',
                            'filter' => array('0' => Yii::t('app', 'Inactive'), '1' => Yii::t('app', 'Active')),
                            'htmlOptions' => array('style' => 'text-align: center;padding:5px;'),
                        ),
                        array(
                            'id' => 'autoId',
                            'header' => 'Delete Image',
                            'class' => 'CCheckBoxColumn',
                            'selectableRows' => '50',
                            'checkBoxHtmlOptions' => array('name' => 'idList[]', 'onclick' => 'deleteAllRecord()', 'class' => 'deleteAllRecord'),
                        ),
                    ),
                ));
                $count = (count($courseWithImage) == '0') ? '' : count($courseWithImage);
               echo '<input type="hidden" name="imagevalidation"  id="imagevalidation" value="' . $count . '">';
                echo '<input type="hidden" name="addimagevalidation"  id="addimagevalidation" value="' . $count . '">';
            } else {
                echo '<input type="hidden" name="imagevalidation" id="imagevalidation" class="imagevalidation" >';
                echo '<input type="hidden" name="addimagevalidation" id="addimagevalidation"  class="addimagevalidation">';
            }
            ?>

        </div>
    </div>

</fieldset> 
<script type="text/javascript">
    function ChangeStatus(id, coursesid)
    {
        if (confirm("Are you sure for make this primary photo?")) {
            $.post("<?php echo Yii::app()->createUrl("courses/primaryImage"); ?>", {id: id, coursesid: coursesid}, function(result) {
                $('#courseimage-grid').yiiGridView.update('courseimage-grid');
            });
        }
    }

</script>

<script type="text/javascript">
    function deleteAllRecord()
    {
        var idList = $(".deleteAllRecord:checked").serialize();
        if (idList)
        {
            if (confirm("Are you sure want to delete?"))
            {
                $.post("<?php echo Yii::app()->createUrl("courses/deleteCourseImage"); ?>", idList, function(response) {
                    location.reload('#courseimage');

                });
            }
        }
    }
    $("#autoId_all").change(function() {
        $('.deleteAllRecord').attr('checked', 'checked');
        var idList = $(".deleteAllRecord:checked").serialize();
        if (idList)
        {
            if (confirm("Are you sure want to delete?"))
            {
                $.post("<?php echo Yii::app()->createUrl("courses/deleteCourseImage"); ?>", idList, function(response) {
                    location.reload('#courseimage');

                });
            }
        }
        $('.deleteAllRecord').removeAttr('checked');

    })


</script>


